﻿/*******************************************************************  
 * Copyright (C) vancl.com
 * All rights reserved. 
 * 
 * Created By: VANCLOA\hanxianlong
 * Create Date:2011/8/19 10:17:57
 * Last Modified By:VANCLOA\hanxianlong
 * Last Modified Date:2011/8/19 10:17:57
 * Description: 请添加对类文件的描述
 * ********************************************************************/
#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace SimpleCodeGenerator.Utility
{
	/// <summary>
	/// 类的说明
	/// </summary>
	public class MyStringBuilder
	{
		private StringBuilder sbBuffer = new StringBuilder();

		private int tabCount = 0;

		/// <summary>
		/// 增加一个Tab缩进
		/// </summary>
		public void IncreaseIndent() {
			tabCount++;
		}

		/// <summary>
		/// 减少一个Tab缩进
		/// </summary>
		public void DecreaseIndent() {
			if (tabCount>0)
			{
				tabCount--;
			}
		}

		/// <summary>
		/// 取消缩进
		/// </summary>
		public void CancelIndent()
		{
			tabCount = 0;
		}

		public MyStringBuilder Append(string value)
		{
			sbBuffer.Append(value);
			return this;
		}

		public MyStringBuilder AppendLine(string value)
		{
			sbBuffer.AppendLine(new string('\t', tabCount) + value);
			return this;
		}

		public MyStringBuilder AppendLine()
		{
			sbBuffer.AppendLine();
			return this;
		}

		public MyStringBuilder AppendFormat(string value, params object[] args)
		{
			sbBuffer.AppendFormat(new string('\t', tabCount) + value,args);
			return this;
		}

		public MyStringBuilder AppendNoLineFormat(string value, params object[] args)
		{
			sbBuffer.AppendFormat(value, args);
			return this;
		}

		public override string ToString()
		{
			return sbBuffer.ToString();
		}

		/// <summary>
		/// 从末尾移除cout个字符
		/// </summary>
		/// <param name="count">要移除的字符个数</param>
		public void RemoveFromLast(int count) {
			sbBuffer.Remove(sbBuffer.Length - count, count);
		}

		public int Length { get { return sbBuffer.Length; } }
	}
}
